#文章管理的model
config = require('../config')
Schema = config.Schema
mongoose = config.mongoose

AdSchema = new Schema({
  name :
    type : String
    required : true
  code :
    type : String
    required : true
  ad_category : String
  href :String
  image_file_id : String
  sorder : Number
  updated_at : Date
  begin_date : String
  end_date : String
  content : String
  status : String
  target : String
  src_page : String
  src_site : String
  src_pos : String
  src_land : String
  href2 : String
})


AdSchema.methods.add = (req,cb) ->
  this.name = req.param('name')
  this.code = req.param('code')
  this.href = req.param('href')
  this.ad_category = req.param('ad_category')
  this.image_file_id = req.param('image_file_id')
  this.sorder = req.param('sorder')
  this.begin_date = req.param('begin_date')
  this.end_date = req.param('end_date')
  this.updated_at = new Date
  this.content = req.param('content')
  this.status = req.param('status') || '0'
  this.target = req.param("target") || '_self'
  this.status = req.param('status') || '0'
  this.src_site = req.param('src_site')
  this.src_page = req.param('src_page')
  this.src_pos = req.param('src_pos')
  this.src_land = req.param('src_land')
  this.href2 = req.param('href2')
  
  # this.href2 = req.param('src_site') + '_' + req.param('src_page') + req.param('src_pos') + req.param('src_land')
  # if this.href && this.href.indexOf('?') > 0
  #   this.href2 = this.href + '&_gfsrc=' + req.param('src_site') + '_' + req.param('src_page') + '_'+ req.param('src_pos') + '_' + req.param('src_land')
  # else
  #   this.href2 = prams.href真实真实真实是 + '?_gfsrc=' + req.param('src_site') + '_' + req.param('src_page') + '_'+ req.param('src_pos') + '_' + req.param('src_land')
  this.save cb

exports.Ad = mongoose.model 'Ad', AdSchema